<?php
namespace Admin\Controller;
use Common\Controller\AuthController;
use Think\Controller;
class VideoController extends AuthController {
    /*
     *
     */
    public function index(){
        header("Content-type:text/html;charset=utf-8");
        $val=I('val');
        $val? $where['title']=array('like',"%".$val."%"):'';
        $this->assign('val',$val);
        A('Public')-> page('video', $where, 10, 'index','');
    }



    //添加视频
    public  function add_video(){
        if(IS_POST){
            $m = M('video');
            if (!$m->autoCheckToken($_POST)) {
                $this->error('表单令牌错误', 0, 0);
            }else{
                $data=I();
                $data['add_time']=time();
                $data['images'] = base64ToImage($data['images']);
                if($result=$m->add($data)){
                    $this->error('添加成功',U('Video/index'));
                }
                else{
                    $this->error('添加失败');
                }
            }
        }else{
            $this->assign('id',I('id'));
            $this->display();
        }

    }
    //修改视频
    public  function edit_video(){
        if (IS_POST) {
            $data = I();
            $data['add_time'] = time();
            $data['images'] = base64ToImage($data['images']);
            M('video')->where(array('id' => I('id')))->setField($data)?$this->success('修改成功',U('Video/index')):$this->error('修改失败');
        } else{
            $data = M('video')->where(array('id' => I('id')))->find();
            $this->assign('images',$data['images']);
            $this->assign('data', $data);
            $this->display();
        }
    }
    //删除视频
    public function  del_video(){
        if(M('video')->where(array('id'=>I('id')))->delete()){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }
}